package com.hnyfkj.jyindustry.common.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

/**
 * Created by wz on 2018/3/2.
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response<T> {

    int code;
    String msg;
    long count;
    T data;

    public boolean ok() {
        return code == 0;
    }

    public static <T> Response success() {
        Response<T> response = new Response<>();
        response.code = 0;
        response.msg = "成功";
        return response;
    }

    public static <T> Response success(T data) {
        Response<T> response = new Response<>();
        response.code = 0;
        response.msg = "成功";
        response.data = data;
        return response;
    }


    public static <T> Response success(long count, T data) {
        Response<T> response = new Response<>();
        response.code = 0;
        response.msg = "成功";
        response.count = count;
        response.data = data;
        return response;
    }

    public static <T> Response error(String message) {
        Response<T> response = new Response<>();
        response.code = 1;
        response.msg = message;
        return response;
    }

    public static <T> Response auth() {
        Response<T> response = new Response<>();
        response.code = 2;
        response.msg = "认证失败";
        return response;
    }
}
